package com.shell.customer.register.rx;

import com.shell.bee.base.utils.StringUtil;
import com.shell.bee.base.utils.SystemUtil;
import com.shell.customer.base.service.CusRecService;
import com.shell.customer.register.RegisterEvent;
import com.shell.customer.register.vo.RegisterVo;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SaveCusSubscriber extends OnErrorNotImplementedSubscriber<RegisterEvent> {
	@Autowired
	private CusRecService customerCService;

	public void onApplicationEvent(RegisterEvent event) {
		RegisterVo registerVo = event.getRegisterVo();

		registerVo.setCusId(SystemUtil.getUUID());
		registerVo.setCusState("1");
		if (StringUtil.emptyAndNull(registerVo.getContactorId())) {
			registerVo.setContactorId(SystemUtil.getUUID());
		}
		this.customerCService.save(registerVo);
	}
}
